<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            <input type="text" name="classification_name" lay-verify="required|classification_name" required placeholder="分类名称" class="layui-input" id="classification_name">
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="search">搜索</button>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-normal" data-url="{:url('addCate')}" onclick="add_t(this,'添加商品分类')">
                添加
            </button>
        </div>
    </blockquote>

    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Point/indexCate')}', page: true, limit: 10, id:'test'}" lay-filter="test">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'classification_id', width:100,align:'center', fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'classification_name', width:200,align:'center'}">名称</th>
            <th lay-data="{field:'sort', width:200,align:'center'}">排序</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:200, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="editCate" style="width: 50px">修改</a>
        <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delCate" style="width: 50px">删除</a>-->
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var classification_id = data.classification_id;

                if (obj.event === 'delCate') {
                    layer.confirm('确定删除吗?',function(index){
                        var url = '{:url("/admin/Point/delCate","classification_id=")}' + classification_id
                        $.get(url,function(data){
                            if(data.status == 1){
                                layer.msg('成功删除',{'icon':1});
                                window.location.reload();
                            }else{
                                layer.msg('操作失败',{'icon':2});
                            }
                        },'json')
                        layer.close(index);
                    })
                } else if (obj.event === 'editCate') {
                    layer.open({
                        type: 2,
                        title: '商品分类修改',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/Point/editCate","classification_id=")}' + classification_id //iframe的url
                    });

                }
            });
            //搜索
            $('.layui-btn').on('click', function () {
                var classification_name = $("#classification_name").val();
                table.reload('test', {
                    url: '/admin/Point/indexCate', where: {
                        "classification_name": classification_name,
                    }
                });
            })
        });

    </script>
</block>
